﻿using System.Data;

namespace Tms.BLL
{
    public partial class patient
    {
        private readonly DAL.patient dal = new DAL.patient();
                
        //是否存在
        public bool Exists(int id)
        {
            return dal.Exists(id);
        }
        public bool Exists(string where)
        {
            return dal.Exists(where);
        }
        public bool ExistsNo(string patientNo)
        {
            return dal.ExistsNo(patientNo);
        }

        //增加一条数据
        public int Add(Model.patient model)
        {
            return dal.Add(model);
        }

        //更新一条数据
        public bool Update(Model.patient model)
        {
            return dal.Update(model);
        }

        //删除一条数据
        public bool Delete(int id)
        {
            return dal.Delete(id);
        }
        public bool Delete(string where)
        {
            return dal.Delete(where);
        }
        public bool DeleteNo(string patientNo)
        {
            return dal.DeleteNo(patientNo);
        }

        //获取一个实体对象
        public Model.patient GetModel(int id)
        {
            return dal.GetModel(id);
        }
        public Model.patient GetModel(string patientNo)
        {
            return dal.GetModel(patientNo);
        }

        //获取前几行数据
        public DataSet GetList(int Top, string strWhere, string strOrder)
        {
            return dal.GetList(Top, strWhere, strOrder);
        }

        //获取查询分页数据
        public DataSet GetList(int pageSize, int pageIndex, string strWhere, string strOrder, out int recordCount)
        {
            return dal.GetList(pageSize, pageIndex, strWhere, strOrder, out recordCount);
        }

        //更新主治医生
        public bool UpdateDoctorName(Model.patient model)
        {
            return dal.UpdateDoctorName(model);
        }

        //更新阈值
        public bool UpdateThreshold(string patientNo, string thresholdA, string thresholdB)
        {
            return dal.UpdateThreshold(patientNo, thresholdA, thresholdB);
        }

        //获取最大编号
        public string GetMaxPatientNo(string today)
        {
            return dal.GetMaxPatientNo(today);
        }


        #region 虚拟患者

        //虚拟患者
        public readonly string VirtualPatientNo = "999999999999";  //或者 "000000000000"
        public readonly string VirtualPatientName = "虚拟患者";

        //虚拟患者是否存在
        public bool ExistsVirtualPatient()
        {
            return ExistsNo(VirtualPatientNo);
        }

        //新建虚拟患者
        public void CreateVirtualPatient()
        {
            bool b = ExistsVirtualPatient();
            if (!b)
            {
                string sql = "insert into tms_patient(patient_no, patient_name) values('" 
                    + VirtualPatientNo + "','" + VirtualPatientName + "') ";

                dal.ExecuteSql(sql);
            }            
        }

        //删除虚拟患者
        public void DeleteVirtualPatient()
        {
            DeleteNo(VirtualPatientNo);
        }
        
        //获取虚拟患者
        public Model.patient GetVirtualPatient()
        {
            return GetModel(VirtualPatientNo);
        }

        #endregion

    }
}